<?php
/*
 * Component.php created on 28 avr. 08 
 * Author: Rodrigue Le Gall
 *
 * RPortal is an open source web based Content Management System
 * Copyright (C) 2002-2008  Rodrigue Le Gall
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
/**
 * implementation of the RPortal component concept
 */
class Component {
	/**
	 * This is the id of the component
	 */
	private $id;
	
	public function setId($id){
		$this->id = $id;
	}
	
	public function getId() {
		return $this->id;
	}
	
	/**
	 * instantiate a component that implements a specific interface
	 * @param string $iName the desired implemented name interface
	 * @return Component an component instance
	 */
	protected function getObject($iName) {
		return RPORTAL :: getObject($iName);
	}
	
	/**
	 * get the class name of component that implements the desired interface
	 * @param string $iName the desired implemented name interface
	 * @return string component class name
	 */
	protected function getClass($iName) {
		return RPORTAL :: getClass($iName);
	}
	
	//Component management : static part
	
	private static $components = array ();
	
	
	/**
	 * register the component in RPortal core
	 * @param Component $component the component object to register
	 */
	public static function registerComponent(Component $component){
		Component :: $components[$component->getId()] = $component;
	}
	
	/**
	 * retrieve the component that was register
	 * @param string $cName the id of the searched component
	 * @return Component null or a component
	 */
	public function search($cName){
		if(!array_key_exists($cName,Component :: $components)) return null;
		return Component :: $components[$cName];
	}
}
